import {defineStore} from 'pinia'
import { AclApi } from "@/api/acl/index.js";

export const useAclStore = defineStore('acl',{
    state:()=>({
       aclList:[],
        queryList:{
            page:1,
            size:10,
            total:0,
            totalPage:0,
            name: "",
            code: "",
            type: ""
        },
        aclDetail:{},
    }),
    actions:{
        async getAclList(){
            const res = await AclApi.getAclList(this.queryList)
            this.aclList = res.data.records
            this.queryList.page = res.data.pageNumber
            this.queryList.size = res.data.pageSize
            this.queryList.total = res.data.totalRow
            this.queryList.totalPage = res.data.totalPage
        },
        async deleteAcl(id){
            const res = await AclApi.deleteAcl(id)
            this.getAclList()
        },
        async updateAcl(data){
            const res = await AclApi.updateAcl(data)
            this.getAclList()
        },
        async getAclDetail(id){
            const res = await AclApi.getAclDetail(id)
            this.aclDetail = res.data
        },
        async createAcl(data){
            const res = await AclApi.createAcl(data)
            this.getAclList()
        }
    }
})